<?php
/* 
* @Author: Administrator
* @Date:   2014-07-27 07:20:21
* @Last Modified by:   Administrator
* @Last Modified time: 2014-07-27 08:39:33
*/


/**
* 简历视图模型
*/
class ResumeViewModel extends ViewModel
{
	public $table='people_resume1';

	public $view = array(
		'people_resume2'=>array(
				'type'=>LEFT_JOIN,
				'on'=>'people_resume1.reid=people_resume2.resume1_reid'
			),
		'people_resume3'	=>	array(
			'type'	=>	LEFT_JOIN,
			'on'	=>	'people_resume1.reid=people_resume3.resume1_reid'
			),
		'people_resume4'	=>	array(
			'type'	=>	LEFT_JOIN,
			'on'	=>	'people_resume1.reid=people_resume4.resume1_reid'
			),
		'people_resume5'	=>	array(
			'type'	=>	LEFT_JOIN,
			'on'	=>	'people_resume1.reid=people_resume5.resume1_reid'
			),
		'people_resume6'	=>	array(
			'type'	=>	LEFT_JOIN,
			'on'	=>	'people_resume1.reid=people_resume6.resume1_reid'
			),
		'people_resume7'	=>	array(
			'type'	=>	LEFT_JOIN,
			'on'	=>	'people_resume1.reid=people_resume7.resume1_reid'
			)
		);


	public function get_join_resume($uid=NULL)
	{
		$reid = Q('get.reid',0,'intval');
		if (!$reid) return false;

		$where=array(
				'resume1_reid'=>$reid,
				'user_uid'=>$uid
			);
		if(!$uid) unset($where['user_uid']);

		$data = $this->join('people_resume7')->where($where)->find();
		
		//处理审核状态
		switch ($data['verifystate']) {
			case 1:
				$data['verifystate'] = '审核中';
				break;
			case 2:
				$data['verifystate'] = '审核通过';
				break;
			case 3:
				$data['verifystate'] = '审核失败';
				break;
		}

		//处理公开状态
		// 0为半公开，1为全部公开
		switch ($data['publicstate']) {
			case 0:
				$data['publicstate'] = '半公开';
				break;
			case 1:
				$data['publicstate'] = '公开';
				break;
		}
		//处理简历完整度
		$data['progress'] = K('Resume1')->get_progress($reid);
		//照片审核状态
		$faceValidate = $data['facevalidate'] ? $data['facevalidate'] : 3;

		switch ($faceValidate) {
			case 1:
				$data['facevalidate'] = '审核中';
				break;
			case 2:
				$data['facevalidate'] = '审核通过';
				break;
			default:
				$data['facevalidate'] = '未上传照片';
				break;
		}


		//处理有效时间
		$data['totime'] = date('Y-m-d', $data['sendtime']) . '——' . date('Y-m-d', $data['endtime']);


		//处理照片公开状态
		//照片审核状态
		$facepublic = $data['facepublic'] ? $data['facepublic'] : 3;
		switch ($facepublic) {
			case 0:
				$data['facepublic'] = '半公开';
				break;
			
			case 1:
				$data['facepublic'] = '完全公开';
				break;

			default:
				$data['facepublic'] = '未上传照片';
				break;
		}
		if($resume2Data = K('Resume2')->get_data($reid)){
			$data['resume2Data'] = $resume2Data;
			#获取职位名
			$data['resume2Data']['posname'] = K('ResumePosView')->get_posname($reid);
			#获取城市名称city_cityid
			$data['resume2Data']['city'] = K('City')->get_cityname($data['resume2Data']['city_cityid']);
			if($resume3Data = K('Resume3')->get_data($reid)){
				$data['resume3Data'] = $resume3Data;
				//处理教育经历
				if($resume4Data = K('Resume4')->get_data($reid)){
					$data['resume4Data'] = $resume4Data;
					//工作经历
					$resume5Data = K('Resume5')->get_data($reid);
					$data['resume5Data'] = $resume5Data;

					//培训经历
					$resume6Data = K('Resume6')->get_data($reid);
					$data['resume6Data'] = $resume6Data;

				}

			}
		}
		// p($data);
		return $data;
	}

	public function get_all()
	{
		$reid = Q('get.reid',0,'intval');
		if (!$reid) return false;

		$where=array(
				'reid'=>$reid,
			);

		$data = $this->join(array('people_resume2','people_resume3','people_resume7'))->where($where)->find();
		$data['height'] = $data['height'] ? $data['height'].'cm' : null;
		if($data['endtime'] < time()){
			echo 111;
			$data['endtime1'] = 0;
		}else{
			$data['endtime1'] = date('Y-m-d',$data['endtime']);
		}
		unset($data['endtime']);
		$data['freshtime'] = date('Y-m-d',$data['freshtime']);
		$data['pos']  = K('ResumePosView')->get_posname($reid);

		if($resume4Data = K('Resume4')->get_data($reid)){
			$data['resume4Data'] = $resume4Data;
			//工作经历
			$resume5Data = K('Resume5')->get_data($reid);
			$data['resume5Data'] = $resume5Data;

			//培训经历
			$resume6Data = K('Resume6')->get_data($reid);
			$data['resume6Data'] = $resume6Data;

		}
		return $data;
	}

	public function get_rand()
	{

		$limit = rand(0,$this->count());
		// p($limit);
		$where=array(
			'publicstate'		=>	1,
			'verifystate'	=>	2,
			'hd_job_people_resume1.endtime'		=>	array('gt'=>time())
		);
		$data = $this->where($where)->limit(array($limit,$limit+5))->all();
		return $data;
	}

}
?>
